<template>
  <div>
    用户名: <input type="text" v-model="name"><br>
    密码: <input type="text" v-model="pwd"><br>

    <button @click="login">登录</button>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "login",
  data() {
    return {
      name: '',
      pwd: ''
    }
  },
  methods: {
    login() {
      axios({url: 'login', method: 'post', data: {'name': this.name, 'pwd': this.pwd}}).then(res => {
        console.log(res)
        if (res.data.code == 10011) {
          localStorage.setItem('token', res.data.token)
          localStorage.setItem('userid', res.data.userid)
          localStorage.setItem('username', res.data.username)
          localStorage.setItem('url_list', JSON.stringify(res.data.url_list))
          this.$router.push({'name': 'com'})
          alert('登录成功')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>